package com.zx.ishopping.mapper;

import com.github.pagehelper.Page;

import com.zx.ishopping.DTO.UserChangePasswordDTO;
import com.zx.ishopping.DTO.UserPageQueryDTO;
import com.zx.ishopping.VO.UserVo;
import com.zx.ishopping.annotation.AutoFill;
import com.zx.ishopping.entity.User;
import com.zx.ishopping.enums.OperationEnum;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {

    /**
     * 通过用户名查询用户
     * @return
     */
    @Select("select * from users where username = #{username}")
    User getUserByUserName(String username);

    /**
     * 插入新用户信息
     */
    @AutoFill(value =  OperationEnum.INSERT)
    
    void inset( User user);

    /**
     * 通过邮箱查询用户
     * @return
     */

    User getUserByEmail(String email);

    /**
     * 分页查询用户信息
     *
     * @return
     */
    Page<UserVo> pageQuery(UserPageQueryDTO userPageQueryDTO);


    /**
     * 修改用户信息
     * @param user
     */
    @AutoFill(value = OperationEnum.UPDATE)
    void update(User user);

    /**
     * 根据用户id查询用户
     *
     * @param id
     * @return
     */
    @Select("select * from users where id = #{id}")
    UserVo getUserById(Long id);

    /**
     * 删除用户
     * @param id
     */
    @Delete("delete from users where id = #{id}")
    void deleteUser(Long id);

    /**
     * 忘记密码
     * @param userChangePasswordDTO
     */
    @Update("update users set password = #{newPassword} where email = #{email}")
    @AutoFill(value = OperationEnum.UPDATE)
    void changePassword(UserChangePasswordDTO userChangePasswordDTO);

    /**
     * 通过id查询密码
     * @param id
     * @return
     */
    @Select("select password from users where id = #{id}")
    String getPassword(Long id);

    /**
     * 根据id修改密码
     * @param userChangePasswordDTO
     */
    @AutoFill(value = OperationEnum.UPDATE)
    @Update("update users set password = #{newPassword} where id = #{id}")
    void changePasswordById(UserChangePasswordDTO userChangePasswordDTO);
}
